<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>下拉菜单改变文字颜色</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            max-width: 400px;
            margin: 0 auto;
            padding: 20px;
        }
        .container {
            display: flex;
            flex-direction: column;
            gap: 15px;
        }
        select {
            padding: 8px;
            font-size: 16px;
            width: 200px;
        }
        button {
            padding: 10px;
            background-color: #4CAF50;
            color: white;
            border: none;
            cursor: pointer;
            font-size: 16px;
            width: 100px;
        }
        button:hover {
            background-color: #45a049;
        }
        #colored-text {
            margin-top: 20px;
            font-size: 20px;
            font-weight: bold;
            transition: color 0.3s;
        }
    </style>
</head>
<body>
    <h2>选择文字颜色</h2>
    <div class="container">
        <select id="color-select">
            <option value="">-- 请选择颜色 --</option>
            <option value="red">红色</option>
            <option value="yellow">黄色</option>
            <option value="blue">蓝色</option>
            <option value="green">绿色</option>
        </select>
        <button onclick="changeColor()">确定</button>
        <div id="colored-text">这段文字的颜色会随选择改变</div>
    </div>

    <script>
        function changeColor() {
            const select = document.getElementById('color-select');
            const coloredText = document.getElementById('colored-text');
            const selectedColor = select.value;
            
            if (selectedColor === "") {
                alert("请先选择一个颜色");
                return;
            }
            
            coloredText.style.color = selectedColor;
        }
    </script>
</body>
</html>